"""
ResumeMyWay
An app which allows you to create an online personal professional journal and 
easily generate different versions of your resume for different purposes.

Copyright (c) 2011 Jay Baxter, Saher Ahwal, Wesam Manassra, Arun Saigal
"""

from flask import g, session, request
#from flaskext.sqlalchemy import SQLAlchemy
from string import strip
import time
from .. import db

class User(db.Model):
    # this declaration results in an autoincrementing id
    id = db.Column(db.Integer, primary_key=True)

    first = db.Column(db.String)
    last = db.Column(db.String)
    email = db.Column(db.String, unique=True)
    password = db.Column(db.String)

    def __init__(self, dict):
        self.first = strip(dict['first'])
        self.last = strip(dict['last'])
        self.email = strip(dict['email'])
        self.password = dict['password']

    def __repr__(self):
        return '<User %r>' % self.email

    @staticmethod
    def get_by_email(email):
        """Return first user with given email address or None if no such user"""
        u = User.query.filter_by(email=email).first()
        return u